package com.tim.spring.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class JDKProxy implements InvocationHandler {
	private Object target;

	public JDKProxy(Object target) {
		this.target = target;
	}

	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		Object obj = null;
		TestAspect aspect = new TestAspect();
		// 前置通知
		aspect.before();
		try {
			// 方法执行
			obj = method.invoke(target, args);
			// 后置通知
			aspect.afterReturning();
		} catch (Exception e) {
			AfterThrowingExample throwingAspect = new AfterThrowingExample();
			throwingAspect.afterThrowingExample(e);
		} finally {
			// 最终通知
			aspect.after();
		}
		return obj;
	}

}
